import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

const state = {
    token: "",
    currentPage: 1
};

const mutations = {
    setToken(state, token) {
        state.token = token;
        localStorage.setItem("token", token);
    },
    setPage(state, currentPage) {
        state.currentPage = currentPage;
    },
    logout(state) {
        state.token = "";
        localStorage.removeItem("token");
    }
};

const getters = {
    isLogin(state) {
        if(state.token || localStorage.getItem("token")) {
            return true;
        } else {
            return false;
        }
    }
};

const store = new Vuex.Store({
    state,
    mutations,
    getters
});

export default store;

